<?php
session_cache_expire(999999999);
if (!isset($_SESSION)) {
    session_start();
}
$lang = $_SESSION['lang'];
if (empty($lang) || $lang == "EN") {
    include "../../value/value_en.php";
} else if ($lang == "VN") {
    include "../../value/value_vn.php";
} else {
    include "../../value/value_kr.php";
}
include '../../operations/connection.php';
$stonggiacungcap = 0;
$stongthue = 0;
$stongtien = 0;
$mangqui = array("('1','2','3')", "('4','5','6')", "('7','8','9')", "('10','11','12')");
if (isset($_REQUEST['loaitimkiem'])) {
	$qui = $mangqui[$_REQUEST['qui'] - 1];
	$idapprove=$_REQUEST['idapprove'];
	$IDEmployeeSend=$_REQUEST['IDEmployeeSend'];
    //and year(or_order_tax.$time) = '" . $_REQUEST['nam'] . "' )
    $sql="SELECT a.IDApproveDoc,DATE_FORMAT(a.Timecreate, '%Y-%m-%d') as Timecreate,DATE_FORMAT(a.TimeApprove, '%Y-%m-%d') as TimeApprove,buy.*
FROM approvedoc a,listapprove b,buying_document buy
WHERE a.IDGroupApprove=b.IDGroupApprove  AND b.IDEmployee =  '1322887525530' AND a.IDTypeDoc != 11 
		AND a.IDStatus = 1 AND b.IDLabel < 1 AND b.IDStatus = 1 
		AND a.Timecreate>'2010-09-03 00:00:00' AND a.Timecreate<'2013-09-03 23:59:59' 
		AND a.IDApproveDoc=buy.document_id AND buy.company LIKE '%".$_REQUEST['cusname']."%'  ";
	if($IDEmployeeSend!="ALL"){
    	$sql.="	AND  a.IDEmployee = $IDEmployeeSend ";
    }
	if($idapprove==0){
		$sql.="	AND (a.IDTypeDoc = 13 OR a.IDTypeDoc = 15 OR a.IDTypeDoc = 17 OR a.IDTypeDoc = 19 ) ";
	}else{
		$sql.="	AND a.IDTypeDoc =$idapprove ";
	}
	

	$sql.= "AND month(a.Timecreate)  in " . $qui . " AND year(a.Timecreate) = '". $_REQUEST['nam'] ."'";
	
	
	$sql.="	ORDER BY a.Timecreate DESC;";
	//echo $sql;
	//echo $sql;
    $_SESSION['sqlinvoice1'] = $sql;
    

    $sqlinvoice = mysql_query($sql);
    $dem = 0;
	$ob=array();
    if (mysql_num_rows($sqlinvoice) > 0) {
        while ($row = mysql_fetch_array($sqlinvoice)) {
            $dem++;
            $ktdate=getdate(strtotime($row['Timecreate']));
            $ob[$ktdate['year'] . '-' . $ktdate['mon']][]=array($row['IDApproveDoc'],$row['Timecreate'],$row['TimeApprove'],$row['id'],$row['company'],$row['name'],$row['amount'],$row['price'],$row['vat']);
        }
        
        $_SESSION['manginvoicetax'] = $ob;
    }
    
}

$addressbrowser = $_SERVER['SERVER_NAME'];
$temp = explode(".", $addressbrowser);
$queryDepartment = mysql_query("SELECT d.IDDepartment,dl.DepartmentName FROM department d,department_lang dl WHERE d.IDDepartment=dl.IDDepartment AND dl.LangID='$lang';");
$querySendMail = mysql_query("SELECT e.IDEmployee,e.FullName FROM list_sendmail l,employee e WHERE l.employee_id=" . $_SESSION['IDEmployee'] . " AND e.IDEmployee=l.employee_id_sendmail GROUP BY l.employee_id_sendmail");
include '../../popup/popup_reference1.php';
?>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<div class="title2">
        <!--  <span style="float:left"><?php echo $l_company_name ?> : ELisoft</span>
        <span style="float:right">
    <?php

    ?>
        
			        </span>-->
    <input type="hidden" id="orderid" value=""/>
    <input type="hidden" id="lang" value=""/>
    <input type="hidden" id="company" value="" />
</div>
<div style="clear:both"></div>
<div style="position:relative" id="listEmp" >
    <div>
        <table width="100%" border="0" class="ftable" >
            <tr>
                <th style="width: 2%;min-width: 40px"><!-- <a onclick="delorder('<?= $_REQUEST['loaitimkiem'] ?>',<?= $status ?>,'<?= $typedate ?>','',<?= $dem ?>)"><img src="images/del.png" title="<?php echo $l_delete; ?>"/></a> --></th>
                <th style="width: 2%;min-width: 40px" ><label><input type="checkbox" checked="checked" id="check_no"><?= $l_no ?></label></th>
                <th style="width: 10%;min-width: 100px"><label><input type="checkbox" checked="checked" id="check_created_date"><?= $l_created_date ?></label></th>
                <th style="width: 18%;min-width: 220px"><label><input type="checkbox" checked="checked" id="check_company_name"><?= $l_company_name ?></label></th>
                <th style="width: 35%;min-width: 220px"><label><input type="checkbox" checked="checked" id="check_product_item"><?= $l_product_item ?></label></th>
                <th style="display: none;"><label><input type="checkbox" id="check_quantity"><?= $l_quantity ?></label></th>
                <th style="width: 8%;min-width: 80px"><label><input type="checkbox" checked="checked" id="check_Supply_price"><?= $l_Supply_price ?></label></th>
                <th style="width: 8%;min-width: 80px"><label> <input type="checkbox" checked="checked" id="check_vat"><?= $l_vat ?></label></th>
                <th style="width: 8%;min-width: 80px"><label><input type="checkbox" checked="checked" id="check_amount"><?= $l_amount ?></label></th>
                <th style="width: 10%;min-width: 100px"><label><input type="checkbox" id="check_approve_date"><?= $l_approve_date ?></label></th>
                <th style="width: 8%;min-width: 80px"></th>
            </tr>

            <?php
            $soluong = $dem;
            if ($soluong > 0) {
                $vitri = 0;
                foreach ($ob as $value => $mgiatri) {
                    $tonggiacungcap = 0;
                    $tongthue = 0;
                    $tongtien = 0;
                    $dem = count($mgiatri);
                    $d = 0;
                    if ($dem > 0) {
                        for ($i = 0; $i < $dem; $i++) {
                       
                            ?>
                            <tr>
                                <td><input type="checkbox" id="check<?=$vitri ?>" name="check<?= $vitri ?>" value="<?= $mgiatri[$i][3]?>" /></td>
                                <td style="padding: 5px;"><?=($vitri + 1) ?></td>
                                <td><?= $mgiatri[$i][1] ?></td>
                                <td style="text-align:left"><?=$mgiatri[$i][4]?></td>
                                <td style="text-align:left"><?=$mgiatri[$i][5]?></td>
                                <td style="display: none;"><?= number_format($mgiatri[$i][6]) ?></td>
                                <td style="text-align:right;"><?=number_format($mgiatri[$i][7]*$mgiatri[$i][6]) ?></td>
                                <td style="text-align:right;"><?=number_format($mgiatri[$i][8]*$mgiatri[$i][6]) ?></td>
                                <td style="text-align:right;"><?=number_format($mgiatri[$i][7]*$mgiatri[$i][6]+$mgiatri[$i][8]*$mgiatri[$i][6]) ?></td>
                                <td><?= $mgiatri[$i][1] ?></td>
                                <td><!-- <img src="images/email.png"  onclick="setdata('<?= $mgiatri->orderid ?>','<?= $lang ?>','<?= $temp[0] ?>')" title="<?= $l_sendmail ?>" /> --></td>
                            </tr>
                            <?php
                             
                             $d++;
                            
                            $tonggiacungcap +=$mgiatri[$i][7]*$mgiatri[$i][6];
                            $tongthue +=$mgiatri[$i][8]*$mgiatri[$i][6];
                            $tongtien +=($mgiatri[$i][7]*$mgiatri[$i][6]+$mgiatri[$i][8]*$mgiatri[$i][6]);
                            $vitri++;
                        }
                    }
                    ?>
                    <tr class="coltr2" style="font-weight:bold;font-size:14px;">
                        <td colspan="5"  style="padding: 10px;">
                            <?php
                            if ($_REQUEST['loaitimkiem'] == "thang") {
                                ?>
                                <?php echo $l_month; ?> : <font color="red"><?php echo $value; ?></font>  -  <?php echo $l_co; ?> : <font color="blue"><?php echo number_format($d); ?></font> 
                                <?php
                            } else if ($_REQUEST['loaitimkiem'] == "qui") {
                                ?>
                                <?php echo $l_month; ?> : <font color="red"><?php echo $value; ?></font>  -  <?php echo $l_co; ?> : <font color="blue"><?php echo number_format($d); ?></font> 
                                <?php
                            } else if ($_REQUEST['loaitimkiem'] == "all") {
                                ?>
                                <?php echo $l_month; ?> : <font color="red"><?php echo $value; ?></font>  -  <?php echo $l_co; ?> : <font color="blue"><?php echo number_format($d); ?></font> 
                                <?php
                            }
                            ?>
                        </td>
                        <td style="display: none;"></td>
                        <td style="text-align:right;"><?php echo number_format($tonggiacungcap); ?></td>
                        <td style="text-align:right;"><?php echo number_format($tongthue); ?></td>
                        <td style="text-align:right;"><?php echo number_format($tongtien); ?></td>
                        <td></td>
                        <td></td>
                        <td></td>
                    </tr>
                    <?php
                    $stonggiacungcap +=$tonggiacungcap;
                    $stongthue +=$tongthue;
                    $stongtien +=$tongtien;
                }
            } else {
                ?>
                <tr><td colspan="12" style="height:30px;text-align:left;padding-left:20px;"><?php echo $l_list_emplty; ?></td></tr>
                <?php
            }
            ?>

            <tr style="font-weight:bold;font-size:15px;color:green;">
                <td colspan="5" style="padding: 10px;"><?php echo $l_tongdon ?></td>
                <td style="display: none;"></td>
                <td style="text-align:right;"><?php echo number_format($stonggiacungcap); ?></td>
                <td style="text-align:right;"><?php echo number_format($stongthue); ?></td>
                <td style="text-align:right;"><?php echo number_format($stongtien); ?></td>
                <td style="text-align:right;"></td>
                <td></td>
                <td></td>
            </tr>
        </table>
    </div>
</div>
<?php
if ($soluong > 0) {
    ?>
    <!--  <div class="fbox2" style="text-align:center; width:100%;">
        <a href="printer/ajax_export_acc.php?type=<?php echo $_REQUEST['loaitimkiem']; ?>&typedate=<?php echo $typedate; ?>&cusname=<?php echo $_REQUEST['cusname']; ?>&df=<?php echo $_REQUEST['df']; ?>&dt=<?php echo $_REQUEST['dt']; ?>&status=<?= $status ?>"><input type="button" value="<?= $l_export_excel ?>" class="btnupbg btnupload" style="background: #4f81bd;"/></a>
        <a onclick="onprinter('<?php echo $_REQUEST['loaitimkiem']; ?>','<?php echo $typedate; ?>','<?php echo $_REQUEST['cusname']; ?>','<?php echo $_REQUEST['nam']; ?>','<?php echo $_REQUEST['thang']; ?>','<?= $status ?>');"><input type="button" value="<?= $l_print ?>" class="btnupbg btnupload" style="background: #4f81bd;"/></a>
    </div>-->
    <?php
}
?>